/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package save;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author Admin
 */
public class OpenFileDialog {

    private static JFileChooser jfcChooser = null;
    private String sDirectory;
    private boolean bIsFile = false;
    private static String filename;

    public OpenFileDialog() {
        if (jfcChooser == null) {
            jfcChooser = new JFileChooser();
            //jfcChooser.addChoosableFileFilter(new ImageFilter());

        }
        int fileState = jfcChooser.showOpenDialog(null);
        File file = jfcChooser.getSelectedFile();
        if (file != null && fileState == JFileChooser.APPROVE_OPTION) {
            setFilePath(file.getAbsolutePath());
            filename = file.getName();

        } else if (fileState == JFileChooser.CANCEL_OPTION) {
            bIsFile = false;
        }
    }

    public String getFilePath() {
        return sDirectory;
    }

    public String getFileName() {
        return filename;
    }

    public boolean isFileSelected() {
        return bIsFile;
    }

    private void setFilePath(String fpath) {
        sDirectory = fpath;
        bIsFile = true;
    }
}
